package xyz.iguilty.workflow.model;

import lombok.Getter;
import xyz.iguilty.workflow.enums.ActorType;

import java.util.ArrayList;
import java.util.List;

@Getter
public class ActorModel {
    public ActorType actorType;
    public List<SimpleUser> assignees;
    public List<SimpleUser> candidateUsers;
    public List<SimpleGroup> candidateGroups;

    private ActorModel(ActorType actorType) {
        this.actorType = actorType;
    }

    private void setAssignees(List<SimpleUser> assignees) {
        this.assignees = assignees;
    }

    private void setCandidateUsers(List<SimpleUser> candidateUsers) {
        this.candidateUsers = candidateUsers;
    }

    private void setCandidateGroups(List<SimpleGroup> candidateGroups) {
        this.candidateGroups = candidateGroups;
    }

    public static ActorModel buildFromAssignee(SimpleUser assignee) {
        ActorModel actorModel = new ActorModel(ActorType.ASSIGNEE);
        List<SimpleUser> assignees = new ArrayList<>();
        assignees.add(assignee);
        actorModel.setAssignees(assignees);
        return actorModel;
    }

    public static ActorModel buildFromAssignee(List<SimpleUser> assignees) {
        ActorModel actorModel = new ActorModel(ActorType.ASSIGNEE);
        actorModel.setAssignees(assignees);
        return actorModel;
    }

    public static ActorModel buildFromCandidateUser(SimpleUser candidateUser) {
        ActorModel actorModel = new ActorModel(ActorType.CANDIDATE_USER);
        List<SimpleUser> simpleUsers = new ArrayList<>();
        simpleUsers.add(candidateUser);
        actorModel.setCandidateUsers(simpleUsers);
        return actorModel;
    }

    public static ActorModel buildFromCandidateUser(List<SimpleUser> candidateUsers) {
        ActorModel actorModel = new ActorModel(ActorType.CANDIDATE_USER);
        actorModel.setCandidateUsers(candidateUsers);
        return actorModel;
    }

    public static ActorModel buildFromCandidateGroup(SimpleGroup candidateGroup) {
        ActorModel actorModel = new ActorModel(ActorType.CANDIDATE_GROUP);
        List<SimpleGroup> candidateGroups = new ArrayList<>();
        candidateGroups.add(candidateGroup);
        actorModel.setCandidateGroups(candidateGroups);
        return actorModel;
    }

    public static ActorModel buildFromCandidateGroup(List<SimpleGroup> candidateGroups) {
        ActorModel actorModel = new ActorModel(ActorType.CANDIDATE_GROUP);
        actorModel.setCandidateGroups(candidateGroups);
        return actorModel;
    }

}
